<template>
	<view class="container">
		<view class="view1">
			<uni-forms :modelValue="form" :rules="rule" ref="form">
				<uni-forms-item label="标题" required label-align="center" name="title">
					<uni-easyinput type="text" placeholder="请输入反馈标题" v-model="form.title"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="内容" required label-align="center" name="content">
					<uni-easyinput type="textarea" placeholder="请输入反馈内容" v-model="form.content"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item label="电话" required label-align="center" name="phone">
					<uni-easyinput type="number" placeholder="请输入手机号" v-model="form.phone"></uni-easyinput>
				</uni-forms-item>
			</uni-forms>
		</view>
		
		<button type="primary" style="width: 80%;margin-top: 40rpx;" @click="send">提交</button>
		<text @click="JumpHistory" class="history">反馈历史</text>
	</view>
</template>

<script>
	import {addfeedback} from '@/until1/api1.js'
	export default {
		data() {
			return {
				form: {
					title: "",
					content: "",
					phone: ""
				},
				username:'',
				rule:{
					title:{rules:[{required:true,errorMessage:'标题不能为空'}]},
					content:{rules:[{required:true,errorMessage:'内容不能为空'}]},
					phone:{rules:[{required:true,errorMessage:'电话不能为空'}]}
				}
			}
		},
		onLoad(options){
			this.username=options.username
		},
		methods:{
			// 提交反馈
			send(){
				this.$refs.form.validate(async (r)=>{
					if (r==null) {
						console.log(this.form);
						let r1=await addfeedback(this.form)
						console.log(r1)
						//判断是否提交成功
						uni.showToast({
							title: r1.msg,
							icon: r1.code == 200 ? "success" : "error"
						 })
						//  //判断完成后返回用户页面
						 setTimeout(()=>{
							 uni.navigateTo({
							 	url:'/pages/mine/index'
							 })
						 },1500)
						 
					}
				})
			},
			JumpHistory(){
				uni.navigateTo({
					// url:'/pages/mine/feedHistory/feedHistory?username='+this.username
					url:'/pages/mine/feedHistory/feedHistory'
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: white;
	}
	.view1 {
		margin: 10rpx 10rpx;
		
	}
	.history{
		margin-top: 30rpx;
		margin-left: 630rpx;
		color:#157EE3;
		font-size: 20rpx;
	}
</style>